package com.digitalart.nav.item {
	import flash.events.Event;      
	
	import com.digitalart.nav.NavController;
	
	import flash.display.Sprite;
	
	import com.digitalart.commons.CustomEvent;
	import flash.events.MouseEvent;
	import com.digitalart.nav.NavModel;
	import com.digitalart.nav.NavItemVO;
	
	import flash.events.EventDispatcher;
	
	
	/**
	 * @author johan.chaves
	 */
	public class NavItemController extends EventDispatcher {                                
		
		public static const ITEM_CLICKED : String = "navItemClicked";
		
		private var _navItemModel : NavItemModel;
		private var _navItemView : NavItem;
		
		
		/**********************************Constructor*************************/
		
		public function NavItemController(itemVO : NavItemVO) {
			super(this);
			_navItemModel = new NavItemModel(itemVO.classAlias);
			_navItemView = new NavItem(itemVO.copy);                        
			_navItemView.addEventListener(MouseEvent.CLICK, onChangeSectionRequest);
		}
		
		/**********************************************************************/
		
		/**********************************Methods*************************/
		
		private function onChangeSectionRequest(e : Event) : void {                     
			_navItemView.isSelected = true;
			dispatchEvent(new CustomEvent(ITEM_CLICKED, _navItemModel.classAlias));
		}
		
		
		/**********************************************************************/
		/**************************Getters & Setters***************************/
		
		public function getView():NavItem{
			return _navItemView;
		}
	}
}